package com.qiaoanju.back.dao.system;

import com.qiaoanju.back.domain.system.RoleModel;
import com.qiaoanju.back.domain.system.UserModel;
import com.qiaoanju.dao.SqlMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * Created by eversec on 2017/10/10.
 */
public interface IRoleDao extends SqlMapper {


    /**
     *
     * @param groupId
     * @return
     */
    @Select("SELECT * FROM t_role WHERE group_id = #{groupId} ")
    List<RoleModel> getRoleByGroupId(int groupId);

    @Select("SELECT * FROM t_role  ")
    List<RoleModel> getRolesList(Map<String, Object> params);

    @Insert("insert into t_role(group_id,role_code,role_name, enable,resource_url,update_time, create_id,update_id) values(#{group_id},#{role_code},#{role_name}, #{enable}, #{resource_url}," +
            "#{update_time}, #{create_id}, #{update_id})")
    int insert(RoleModel role);

    /**
     * 批量删除
     * @param ids
     * @return
     */
    int deleteByIds(int[] ids);

    @Delete("delete from t_role where id = #{id}")
    int deleteById(int id);

    @Select("select * from t_role where id = #{id}")
    RoleModel getRoleById(int id);

    @Update("update t_role set group_id = #{group_id},role_code = #{role_code},role_name = #{role_name}, enable = #{enable}, resource_url = #{resource_url}," +
            "update_time = #{update_time},update_id = #{update_id} where id = #{id}")
    boolean edit(RoleModel editModel);
}
